package com.coocaa.x.service.liteupgrade;

import android.content.Context;

import com.coocaa.x.framework.app.CoocaaApplication;
import com.coocaa.x.service.liteupgrade.aidl.UpgradeInfo;
import com.coocaa.x.service.liteupgrade.aidl.UpgradeParams;

import java.io.File;

/**
 * Created by lu on 15-6-18.
 */

/**
 * 需要升级的app，自己实现一个upgradekernel，并在manifest里面配置上如下meta-data
 * <meta-data
 * android:name="coocaa.x.service.upgrade.kernel"
 * android:value="your kernel class" />
 */
public abstract class LiteUpgradeKernel implements LiteUpgradeDownloader.LiteUpgradeDownloaderListener {
    public static final String META_NAME = "coocaa.x.service.upgrade.kernel";

    protected Context mContext = null;
    protected LiteUpgradeDownloader downloader = null;

    public LiteUpgradeKernel() {
        mContext = CoocaaApplication.getContext();
    }

    /**
     * @param downloader
     */
    public final void setDownloader(LiteUpgradeDownloader downloader) {
        this.downloader = downloader;
    }

    //获取升级包本地保存路径，可重载，默认为本应用的cache目录
    public String getSavePath() {
        return CoocaaApplication.getContext().getCacheDir()
                .getAbsolutePath();
    }

    @Override
    public void onStart() {

    }

    @Override
    public void onProgress(int percent, long downloaded_length, long file_length) {

    }

    @Override
    public void onCancel() {

    }

    @Override
    public void onError(String e) {

    }

    @Override
    public void onSuccess(File f) {

    }

    public void onUpdateFileNotExist() {

    }

    public void onUpdateFilePrepared(String path) {

    }

    public abstract void prepare(UpgradeParams params);

    //获取升级包下载路径
    public abstract String getDownloadUrl();

    //获取升级信息
    public abstract UpgradeInfo getUpgradeInfo();

    public String exec(String cmd, UpgradeParams params) {
        return "";
    }
}
